import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/1/20
 * Time:15:12
 * 异常
 **/

class MyException extends RuntimeException{

    public MyException(String message) {
        super(message);
    }

}

class MyException2 extends Exception{

    public MyException2(String message) {
        super(message);
    }

}

class UserException extends Exception {
    public UserException(String message) {
        super(message);
    }
}
class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}

public class Main {
    private static String userName = "admin";
    private static String password = "123456";

    public static void login(String userName, String password) /*throws UserException, PasswordException*/ {
        if (!Main.userName.equals(userName)) {
            try {
                throw new UserException("用户名错误");
            } catch (UserException e) {
                e.printStackTrace();
            }
        }
        if (!Main.password.equals(password)) {
            try {
                throw new PasswordException("密码错误");
            } catch (PasswordException e) {
                e.printStackTrace();
            }
        }
        System.out.println("登陆成功");
    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        login(username, password);
    }

    public static void main3(String[] args) {
        int a = 10;
        try{
            if(a == 10){
                throw new MyException2("bit");
            }else{

            }

        }catch (MyException2 e){
            e.printStackTrace();

        }

    }

    public static void main2(String[] args) {
        try{
            throw new MyException("bit");
        }catch(MyException e){
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        try{
            //System.out.println(10/0);
            throw new ArithmeticException("nhdny");//参数为异常原因
        }catch(ArithmeticException e){
            e.printStackTrace();
        }
    }
}
